package cn.monkey.chat.server.data;

public interface Results {

    Result<Object> EMPTY_OK = Result.builder().code(ResultCode.OK).build();

    @SuppressWarnings("unchecked")
    static <T> Result<T> ok() {
        return (Result<T>) EMPTY_OK;
    }

    static <T> Result<T> ok(T data) {
        return Result.<T>builder().code(ResultCode.OK).data(data).build();
    }

    static <T> Result<T> fail(Integer code, String msg) {
        return Result.<T>builder().code(code).msg(msg).build();
    }

    static <T> Result<T> fail(String msg) {
        return Result.<T>builder().code(ResultCode.FAIL).msg(msg).build();
    }

    static <T> Result<T> error(Throwable e) {
        return Result.<T>builder().code(ResultCode.ERROR).msg(e.getMessage()).build();
    }
}
